package com.xiaoyao.myframeapp.MvpTest.activity;


import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.xiaoyao.myframeapp.MvpTest.bean.Test;
import com.xiaoyao.myframeapp.MvpTest.contract.TestContract;
import com.xiaoyao.myframeapp.MvpTest.presenter.TestPresenter;
import com.xiaoyao.myframeapp.R;
import com.xiaoyao.myframeapp.mvp.base.BaseActivity;
import com.zhy.android.percent.support.PercentLinearLayout;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * MVP模板
 */
public class TestActivity extends BaseActivity<TestPresenter> implements TestContract.View {

    @BindView(R.id.button)
    Button button;
    @BindView(R.id.ic1)
    ImageView ic1;
    @BindView(R.id.ic2)
    ImageView ic2;
    @BindView(R.id.drawer_layout)
    PercentLinearLayout drawerLayout;
    @BindView(R.id.button1)
    Button button1;
    @BindView(R.id.rtv)
    TextView rtv;
    private boolean ishttp = true;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_test;
    }

    @Override
    protected TestPresenter loadPresenter() {
        return new TestPresenter();
    }

    @Override
    protected void initView() {
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                startActivity(new Intent(TestActivity.this.getBaseContext(), AppIntroActivity.class));

                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        if (ishttp) {
                            ishttp = false;
                            mPresenter.login(
                                    TestActivity.this,
                                    "1", "123456");
                        }
                    }
                }).start();
            }
        });
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (ishttp) {
                    ishttp = false;
                    mPresenter.login(
                            TestActivity.this,
                            "1", "123456");
                }
            }
        });
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {


        String img1 = "http://image-demo.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=image/resize,h_100";
        String img2 = "http://image-demo.oss-cn-hangzhou.aliyuncs.com/example.jpg";

        Glide.with(this)
                .load(img1)
                .skipMemoryCache(false)//跳过内存缓存
                .diskCacheStrategy(DiskCacheStrategy.ALL)//硬盘缓存
                .centerCrop()
//                .crossFade()//加载动画
//                    .transform(new GlideCircleTransform(getActivity()))//Glide圆形图片
//                .transform(new GlideRoundTransform(context))//Glide圆角图片
                .into(ic1);
        Glide.with(this)
                .load(img2)
                .skipMemoryCache(false)//跳过内存缓存
                .diskCacheStrategy(DiskCacheStrategy.ALL)//硬盘缓存
                .centerCrop()
//                .crossFade()//加载动画
//                    .transform(new GlideCircleTransform(getActivity()))//Glide圆形图片
//                .transform(new GlideRoundTransform(context))//Glide圆角图片
                .into(ic2);

    }

    @Override
    protected void otherViewClick(View view) {
    }

    @Override
    public void Success(Test isData) {
        ishttp = true;
        rtv.setText(isData.getNickname()+isData.getToken()+"\n");
    }

    @Override
    public void Fail(String Msg) {
        ishttp = true;

    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
